Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine translation of posts #4307

Merged
merged 11 commits into from
Mar 9, 2024
Merged

Machine translation of posts #4307

merged 11 commits into from
Mar 9, 2024

Conversation

charlag
Copy link
Collaborator

@charlag charlag commented Mar 3, 2024

No description provided.

app/build.gradle Outdated
@@ -40,6 +40,13 @@ android {
buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"")
buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"")
}
compileOptions {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixed my IDE but idk if we should remove it before the release?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't even merge it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the blessed way now is

kotlin {
    jvmToolchain(17)
}

https://developer.android.com/build/jdks#toolchain

@charlag charlag force-pushed the translations branch 2 times, most recently from 40f8cbb to c2fef72 Compare March 3, 2024 22:36
@charlag
Copy link
Collaborator Author

charlag commented Mar 3, 2024

@connyduck bitrise failed for no apparent reason

@charlag charlag marked this pull request as ready for review March 3, 2024 22:43
@charlag charlag requested review from Tak and connyduck March 3, 2024 22:44
Copy link
Collaborator

@Tak Tak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. I've installed it locally, but I don't think any of my instances support translation 😐


val translateItem = menu.findItem(R.id.status_translate)
translateItem.isVisible =
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.getCachedInstanceInfoOrFallback().translationEnabled == true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fetch it here before showing the dropdown but I could also preload it when the screen is opened

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd preload it, otherwise there might be an annoying delay when clicking the more button

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem to be a problem a practice but I can preload!

</task>
<servers />
</component>
</project>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file should be checked in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, was a mistake, slipped in at some point, sorry!

@connyduck
Copy link
Collaborator

It took me a while to figure out why the menu item was not shown for me, even though m.s supports translation. Turns out instance info is never downloaded again when it is already cached, except when going to About/Compose/EditProfile. That needs to change somehow.

Copy link
Collaborator

@connyduck connyduck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works very well 😍

@@ -15,6 +15,9 @@
<item
android:id="@+id/status_copy_link"
android:title="@string/action_copy_link" />
<item
android:id="@+id/status_translate"
android:title="Translate" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be translateable


val translateItem = menu.findItem(R.id.status_translate)
translateItem.isVisible =
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.getCachedInstanceInfoOrFallback().translationEnabled == true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd preload it, otherwise there might be an annoying delay when clicking the more button

android:layout_marginEnd="4dp"
android:maxLines="4"
android:visibility="gone"
tools:visibility="visible" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a lineSpacingMultiplier="1.1", align the button top and bottom to the text, and add 4dp top margin.
Like this:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, currently the first line is aligned with the button text, would you rather center it relative to the text? To me both looks good, I will try your idea with centering!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding between them, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2024-03-05 20-52-33

idk how to both center the button to the text but also not make button overlap above?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding between them, right?

4dp additional padding between username and text, but of course there should also be a bit of padding between text & button.

idk how to both center the button to the text but also not make button overlap above?

A yes when the text is only one line it can overlap 🤔
Some possibilities:

  • another barrier
  • force the text to be at least 2 lines
  • leave it top aligned

I don't care much.

.onFailure {
status.update()
}
.asResult()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just forward the NetworkResult?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's kind of leaking an impl detail to me but if you think it's useless I can just pass it through

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion about either, you can leave it if you want

.setMessage(R.string.notification_clear_text)
.setPositiveButton(android.R.string.ok, (DialogInterface dia, int which) -> clearNotifications())
.setNegativeButton(android.R.string.cancel, null)
.show();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you maybe remove these indendation changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure, sorry!

@@ -211,6 +211,9 @@
<string name="action_copy_link">Copy the link</string>
<string name="action_open_as">Open as %s</string>
<string name="action_share_as">Share as …</string>
<string name="action_translate">Translate</string>
<string name="action_show_original">Show original</string>
<string name="action_show_untransalted">Show untranslated</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the name, but also unused?

@charlag
Copy link
Collaborator Author

charlag commented Mar 5, 2024

I've fixed most things (except for the button position). I had to rebase to get @ApplicationScope

@charlag
Copy link
Collaborator Author

charlag commented Mar 5, 2024

Thank you for catching those issues with instance cache!
@Tak I think you just run into the same bugs tbh

) : ViewModel() {

init {
instanceInfoRepository.precache()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having side-effects in constructor but I don't want to introduce an init() method either

@charlag
Copy link
Collaborator Author

charlag commented Mar 6, 2024

I believe I have addressed everything except for the build.gradle thing, I can take it out, no problem with that

@connyduck
Copy link
Collaborator

We actually wanted to use Java 21 #4235

@charlag
Copy link
Collaborator Author

charlag commented Mar 6, 2024

oh I see
I will remove it

translateItem.isVisible =
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this one when opening the menu for one of my own posts from the detailed view - not sure if we need to nullcheck or otherwise guard the menu item visibility logic

Process: com.keylesspalace.tusky.test, PID: 4953
java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.MenuItem.setVisible(boolean)' on a null object reference
        at com.keylesspalace.tusky.fragment.SFragment$more$1.invokeSuspend(SFragment.kt:221)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:363)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:21)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:88)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
        at com.keylesspalace.tusky.fragment.SFragment.more(SFragment.kt:157)
        at com.keylesspalace.tusky.components.viewthread.ViewThreadFragment.onMore(ViewThreadFragment.kt:377)
        at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.lambda$setupButtons$11(StatusBaseViewHolder.java:717)
        at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.$r8$lambda$2lpNa1dIlwqMDFIdAYaiyDBB3A4(Unknown Source:0)
        at com.keylesspalace.tusky.adapter.StatusBaseViewHolder$$ExternalSyntheticLambda9.onClick(D8$$SyntheticClass:0)
        at android.view.View.performClick(View.java:7448)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810) 
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)      
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we just made the menus programmatically

 - it is not inflated for user's own posts but we didn't check for that
 - some servers return language codes in uppercase and it wasn't
matching Java's lowercase code when it should have
@charlag
Copy link
Collaborator Author

charlag commented Mar 9, 2024

fixed the crash, fixed another issue with language code comparison, rebased again

@connyduck connyduck merged commit fbb2279 into develop Mar 9, 2024
3 checks passed
@connyduck connyduck deleted the translations branch March 9, 2024 15:12
@timnolte
Copy link

timnolte commented Apr 4, 2024

@connyduck & @charlag was there some fix for the instance caching issue? Perhaps I missed it but this will work with instances using either DeepL or LibreTranslate right? I'm not seeing the option to translate posts like I do on Megalodon.

@smiba
Copy link

smiba commented May 3, 2024

Unfortunately not working for me, I get an error "Required value 'mediaAttachments' ([...]) missing" when trying to translate a post.

Running mastodon 4.1.15

@connyduck
Copy link
Collaborator

@smiba Can you give me more details please? Which status are you translating into which language from which mastodon server?

@smiba
Copy link

smiba commented May 4, 2024

@smiba Can you give me more details please? Which status are you translating into which language from which mastodon server?

I forgot which status, but they all behave the same and respond with an error. I think it was Japanese into English though.

It's from the mastodon server I manage: https://woof.tech -- We're running an older version (4.1.15) of Mastodon with backported changes. Not sure if this issue is with all 4.1 instances but I'd imagine so? I haven't made any changes to it's translation API or translation functionality in general
Registration is open if you wish to try it yourself

If there is anything else I can do please let me know, couldn't quickly figure out if I could dump Tusky's logs from my phone without adb etc.

@connyduck
Copy link
Collaborator

@smiba Unfortunately it is not possible to create an account. Clicking the confirmation link shows this screen and the resend does nothing:
Screenshot 2024-05-05 at 07 33 57

Why you don't upgrade to 4.2?

@smiba
Copy link

smiba commented May 5, 2024

@smiba Unfortunately it is not possible to create an account. Clicking the confirmation link shows this screen and the resend does nothing: Screenshot 2024-05-05 at 07 33 57

Why you don't upgrade to 4.2?

Sorry, should be resolved now!

We're running some patches that I've yet to migrate to 4.2, which means we're currently stuck on 4.1. I hope to finally have time soon to migrate everything to 4.2

@connyduck
Copy link
Collaborator

#4422

@smiba
Copy link

smiba commented May 5, 2024

Thank you 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants